package com.xywy.bloodandroid.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xywy.bloodandroid.R;
import com.xywy.bloodandroid.act.DoctorDetailFrameAct;
import com.xywy.bloodandroid.act.OrderDoctorAct;
import com.xywy.bloodandroid.base.BasicAdapter;
import com.xywy.bloodandroid.bean.HotDoctorInfo;
import com.xywy.bloodandroid.util.ImageLoader.ImageCallback;


public class FamousDoctorAdapter extends BasicAdapter<HotDoctorInfo>  {
	public LayoutInflater inflater;

	public FamousDoctorAdapter(Context context, List<HotDoctorInfo> list) {
		super(context, list);
		this.inflater=LayoutInflater.from(context);
		
	}
    @SuppressWarnings("unchecked")
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	final int  i=position;
    	 viewHolder holder;
    	if(convertView==null){
    	 convertView=inflater.inflate(R.layout.item_famous_doctor_recomde, null);
    	holder = new viewHolder();
    	holder.head=(ImageView) convertView.findViewById(R.id.doctor_img);
    	holder.name=(TextView) convertView.findViewById(R.id.doctor_name);
    	holder.hosptail_name=(TextView)convertView.findViewById(R.id.hosptail_name);
    	holder.doctor_appellation=(TextView)convertView.findViewById(R.id.doctor_appellation);
    	holder.recollections=(TextView)convertView.findViewById(R.id.recollections);
    	holder.doctor_honor=(TextView)convertView.findViewById(R.id.doctor_honor);
    	holder.doctor_areas=(TextView)convertView.findViewById(R.id.doctor_areas);
    	
    	holder.is_plus=(ImageView) convertView.findViewById(R.id.is_plus);
    	
    	   convertView.setTag(holder);
    	}else{
    		holder = (viewHolder) convertView.getTag();	
    	}
    	String name=list.get(position).getName();
    	String url=list.get(position).getApp_image();
    	String hosptail_name=list.get(position).getHospital();
    	String title=list.get(position).getTitle();//
    	String recollections=list.get(position).getDepart();
    	String doctor_honor=list.get(position).getTeach();//
    	String doctor_areas=list.get(position).getGoodat();
    	
    	
    	holder.name.setText(name);
    	holder.hosptail_name.setText(hosptail_name);
    	holder.doctor_appellation.setText(title);
    	holder.recollections.setText(recollections);
    	holder.doctor_honor.setText(doctor_honor);
    	holder.doctor_areas.setText(doctor_areas);
    	
    	Drawable cachedImage = loader.loadDrawable(url,
				holder.head, new ImageCallback() {

					@Override
					public void imageLoaded(Drawable imageDrawable,
							ImageView imageView, String imageUrl) {
//						imageView = (ImageView) lsitview
//								.findViewWithTag(imageUrl);
						if (imageView != null && imageDrawable != null) {
							imageView.setBackgroundDrawable(imageDrawable);
						}
					}
				});
    	
    	if(cachedImage==null){
    		holder.head.setBackgroundResource(R.drawable.head);
    	}else{
    		holder.head.setBackgroundDrawable(cachedImage);
    	}
    	
    	
    	String is_plus=list.get(position).getIs_plus();
    	if(!"1".equals(is_plus)){
    		holder.is_plus.setVisibility(View.GONE);
    	}else{
    		holder.is_plus.setVisibility(View.VISIBLE);
    	}
    	holder.is_plus.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent1=new Intent(context, OrderDoctorAct.class);
	             Bundle bundle = new Bundle();
	             bundle.putSerializable("HotDoctorInfo", list.get(i));
	             intent1.putExtras(bundle);
	             context.startActivity(intent1);
			}
		});
    	convertView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent=new Intent(context, DoctorDetailFrameAct.class);
	             Bundle bundle = new Bundle();
	             bundle.putSerializable("HotDoctorInfo", list.get(i));
	             intent.putExtras(bundle);
	             context.startActivity(intent);
			}
		});
    	
    	return convertView;
    	
    	
    }
	public class viewHolder {
		
		ImageView head;
		TextView name;
		TextView hosptail_name;
		TextView doctor_appellation;
		TextView recollections;
		TextView doctor_honor;
		TextView doctor_areas;
		
		ImageView is_plus;
		
	}
	
}
